﻿<!-- Atdl4net Sample Code - License and Use
  
     This sample code is provided as part of Atdl4net, with the intention of making it easier to get started.
  
     Whilst Atdl4net is itself made available under either a commercial or an open-source (LGPL) license, the
     samples provided with Atdl4net are made available for use freely by anyone that obtains a copy of
     Atdl4net, without restriction.
  
     For the avoidance of doubt, you are at liberty to remove this statement from any sample code that you
     adapt for your use, but in any case the following statement still applies:
  
     The samples for Atdl4net are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY; 
     without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  
-->
<Window x:Class="Atdl4net.ExampleApplication.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:atdl4net="clr-namespace:Atdl4net.Wpf;assembly=Atdl4net"
        xmlns:root="clr-namespace:Atdl4net.ExampleApplication"
        xmlns:model="clr-namespace:Atdl4net.ExampleApplication.Models" 
        xmlns:conv="clr-namespace:Atdl4net.ExampleApplication.Converters"
        xmlns:mvvm="clr-namespace:Atdl4net.ExampleApplication.Commands"
        Title="Atdl4net Demo Application" SizeToContent="WidthAndHeight">
    
    <Window.Resources>
        <model:MainViewModel x:Key="MainViewModelResource"/>
        <mvvm:CommandReference x:Key="InitializeCommandReference" Command="{Binding InitializeCommand}"/>
        <mvvm:CommandReference x:Key="UpdateFixCommandReference" Command="{Binding UpdateFixCommand}"/>
        <mvvm:CommandReference x:Key="GetOutputValuesCommandReference" Command="{Binding GetOutputValuesCommand}"/>
        <conv:EnumRadioButtonConverter x:Key="EnumRadioButtonConverterResource"/>
        <root:ValidityProcessor x:Key="ValidityProcessorResource"/>
    </Window.Resources>

    <Grid DataContext="{StaticResource MainViewModelResource}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <!-- row 0, column 0 -->
        <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Vertical">

            <GroupBox Margin="2" Padding="3" Width="Auto">
                <GroupBox.Header>
                    <Label>Example Strategies</Label>
                </GroupBox.Header>
                <StackPanel Orientation="Vertical">
                    <TextBlock Margin="4">Select algorithm provider:</TextBlock>
                    <ComboBox ItemsSource="{Binding Path=AlgorithmProviders, Mode=OneWay}" 
                              Width="150" SelectedValue="{Binding Path=SelectedProvider, Mode=OneWayToSource}"/>
                    <TextBlock Margin="4">Select strategy:</TextBlock>
                    <ComboBox Name="StrategySelectionCombo" ItemsSource="{Binding Path=AvailableStrategies, Mode=OneWay}" 
                              DisplayMemberPath="UiRep" SelectedValuePath="Name" 
                              SelectedItem="{Binding Path=SelectedStrategy, Mode=OneWayToSource}"
                              Width="150" />
                </StackPanel>
            </GroupBox>

            <GroupBox Margin="2" Padding="3" Width="Auto">
                <GroupBox.Header>
                    <Label>Strategy Initialization</Label>
                </GroupBox.Header>
                <StackPanel Orientation="Vertical">
                    <TextBlock Margin="0,0,0,2">Order type:</TextBlock>
                    <RadioButton Margin="15,2,0,0" 
                                 IsChecked="{Binding Path=DataEntryMode, Converter={StaticResource EnumRadioButtonConverterResource}, ConverterParameter=Create}">Create order</RadioButton>
                    <RadioButton Margin="15,0,0,0"
                                 IsChecked="{Binding Path=DataEntryMode, Converter={StaticResource EnumRadioButtonConverterResource}, ConverterParameter=Amend}">Amend order</RadioButton>
                    <RadioButton Margin="15,0,0,2"
                                 IsChecked="{Binding Path=DataEntryMode, Converter={StaticResource EnumRadioButtonConverterResource}, ConverterParameter=View}">View order</RadioButton>
                    <TextBlock Margin="0,10,0,2">Initial FIX values:</TextBlock>
                    <TextBox Height="140" Width="150" Margin="2,0,0,2" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"
                             Text="{Binding Path=InitialValuesString}">
                        <TextBox.ToolTip>
                            <TextBlock>Enter fields in the format tag=value|<LineBreak/>e.g. 11=123|38=10000|59=2|...</TextBlock></TextBox.ToolTip>
                    </TextBox>
                    <Button Margin="0,2,0,2" Command="{Binding InitializeCommand}">Initialize</Button>
                </StackPanel>
            </GroupBox>

            <GroupBox Margin="2" Padding="3" Width="Auto">
                <GroupBox.Header>
                    <Label>FIX Value Updates</Label>
                </GroupBox.Header>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Grid.Column="0" Margin="0,10,4,2">FIX tag:</TextBlock>
                    <TextBox Grid.Row="0" Grid.Column="1" Margin="2,10,0,2" Text="{Binding Path=UpdateFixTag, TargetNullValue={x:Static sys:String.Empty}}"/>
                    <TextBlock Grid.Row="1" Grid.Column="0" Margin="0,2,4,2">FIX value:</TextBlock>
                    <TextBox Grid.Row="1" Grid.Column="1" Margin="2,2,0,2" Text="{Binding Path=UpdateFixValue}"/>
                    <Button Grid.Row="2" Grid.ColumnSpan="2"  Margin="0,10,0,2" Command="{Binding UpdateFixCommand}">Update</Button>
                </Grid>
                
            </GroupBox>

        </StackPanel>

        <!-- row 0, column 1 -->
        <Border Grid.Row="0" Grid.Column="1" BorderBrush="Silver" BorderThickness="1" CornerRadius="2"
                Margin="3" Background="White">
            <Grid >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <atdl4net:AtdlControl x:Name="AtdlControl1" Grid.Row="0" Grid.Column="0"
                                      Strategy="{Binding Path=SelectedStrategy, Mode=OneWay}"
                                      InputFixValues="{Binding Path=InitialFixValues, Mode=OneWay}"
                                      DataEntryMode="{Binding Path=DataEntryMode, Mode=OneWay}"
                                      OutputFixValues="{Binding Path=OutputFixValues, Mode=OneWayToSource}"/>
            </Grid>
        </Border>

        <!-- row 1, column 0 -->
        <CheckBox Grid.Row="1" Grid.Column="0" IsEnabled="False" VerticalAlignment="Center" Margin="2" Foreground="Black"
                  IsChecked="{Binding Source={StaticResource ValidityProcessorResource}, Path=IsValid, Mode=OneWay}">Strategy can be submitted</CheckBox>
        <TextBlock Grid.Row="1" HorizontalAlignment="Right" Margin="5"></TextBlock>

        <!-- row 1, column 1 -->
        <Grid Grid.Row="1" Grid.Column="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TextBox Grid.Column="0" Margin="3" Text="{Binding Path=OutputFixMessage, Mode=OneWay}" IsReadOnly="True"/>
            <Button Grid.Column="1" Width="80" Margin="3" Command="{Binding GetOutputValuesCommand}">Get Output</Button>
        </Grid>

    </Grid>
</Window>
